package com.nce.web;   
  
import java.util.List;

import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.convention.annotation.Results;
import org.springframework.beans.factory.annotation.Autowired;
import org.springside.modules.orm.Page;
import org.springside.modules.orm.PropertyFilter;
import org.springside.modules.utils.web.struts2.Struts2Utils;

import com.nce.entity.MblogVip;
import com.nce.service.MblogVipService;
import com.nce.util.LoginUserUtil;
  
@Namespace("/mblogvip")
@Results( { @Result(name = CrudActionSupport.RELOAD, location = "mblogvip.action", type = "redirect") })
public class MblogvipAction extends CrudActionSupport<MblogVip> {   
  
    /**  
     *   
     */  
    private static final long serialVersionUID = 6340167538296898588L;   
  
    @Autowired
    private MblogVipService mblogVipService;
    
     
  
    // 定义返回的对象   
    private Long id;
    private List<MblogVip> entitys;   
    private Page<MblogVip> page = new Page<MblogVip>(10);//每页10条记录
    private MblogVip entity;
    
    
    
    
	public Long getId() {
		return id;
	}
	public void setId(Long id) {
		this.id = id;
	}
		
	
	public MblogVip getEntity() {
		return entity;
	}
	public void setEntity(MblogVip entity) {
		this.entity = entity;
	}
	public List<MblogVip> getEntitys() {
		return entitys;
	}
	public void setEntitys(List<MblogVip> entitys) {
		this.entitys = entitys;
	}
	public Page<MblogVip> getPage() {
		return page;
	}
	public void setPage(Page<MblogVip> page) {
		this.page = page;
	}
	public String list(){
		List<PropertyFilter> filters = PropertyFilter.buildFromHttpRequest(Struts2Utils.getRequest());
		PropertyFilter pf = new PropertyFilter("EQL_user.id", LoginUserUtil.getUser().getId().toString());
		filters.add(pf);
		//设置默认排序方式
		if (!page.isOrderBySetted()) {
			page.setOrderBy("id");
			page.setOrder(Page.ASC);
		}
		page = mblogVipService.searchMblogVipPage(page, filters);
		return SUCCESS;
	}
  
	public String save(){
		entity.setUser(LoginUserUtil.getUser());
		mblogVipService.saveMblogVip(entity);
		addActionMessage("保存重点微博成功");
		return RELOAD;
	}
	@Override
	public MblogVip getModel() {
		return entity;
	}
	@Override
	public String input() throws Exception {
		return INPUT;
	}
	@Override
	public String delete() throws Exception {
		mblogVipService.deleteMblogVip(id);
		addActionMessage("删除重点微博成功");
		return RELOAD;
	}
	@Override
	protected void prepareModel() throws Exception {
		if(id!=null){
			entity = mblogVipService.getMblogVip(id);
		}else{
			entity = new MblogVip();
		}		
	}
}